﻿using NUnit.Framework;
using FluentNHibernate.Testing;
using AdventureWorks.Domain;
using System;
using NHibernate;
using AdventureWorks.DataAccess.Utils;
namespace AdventureWorks.DataAccess.Test.Mappings
{
    [TestFixture]
    public class PersistanceMappingTest 
    {
        private ISession session;
        private ITransaction transaction;
        [SetUp]
        public void Setup()
        {
            session = SessionManager.SessionFactory.OpenSession();
            transaction = session.BeginTransaction();
            session.FlushMode = FlushMode.Always;
        }

        [TearDown]
        public void Teardown()
        {
            transaction.Rollback();
            session.Close();
        }

        [Test]
        public void Vendor_Test()
        {
            var vendor = new Vendor { Name = "Any name", CreditRating = 3, Active = true, PreferredVendorStatus = true, AccountNumber = "Acc Number" , PurchasingWebServiceUrl = "some url"};
            new PersistenceSpecification<Vendor>(session)
            .CheckProperty(p => p.AccountNumber, vendor.AccountNumber)
            .CheckProperty(p => p.Active, vendor.Active)
            .CheckProperty(p => p.CreditRating, vendor.CreditRating)
            .CheckProperty(p => p.Name, vendor.Name)
            .CheckProperty(p => p.PreferredVendorStatus, vendor.PreferredVendorStatus)
            .CheckProperty(p => p.PurchasingWebServiceUrl, vendor.PurchasingWebServiceUrl)
            .VerifyTheMappings();
        }

        [Test]
        public void Person_Test()
        {
            var person = new Employee { FirstName = "first name", LastName = "last name", MiddleName = "E", Suffix = "Jr.", PersonType = "EM", Title = "Mr." };
            new PersistenceSpecification<Person>(session)
            .CheckProperty(p => p.FirstName, person.FirstName)
            .CheckProperty(p => p.LastName, person.LastName)
            .CheckProperty(p => p.MiddleName, person.MiddleName)
            .CheckProperty(p => p.PersonType, person.PersonType)
            .CheckProperty(p => p.Suffix, person.Suffix)
            .CheckProperty(p => p.Title, person.Title)
            .VerifyTheMappings();
        }

        [Test]
        public void SpecialOffer_Test()
        {
            var specialOffer = new SpecialOffer { Category = "Special", Description = "Desc", DiscountPct = 34.2m, Type = "Type", StartDate = new DateTime(2002, 3, 5), EndDate = new DateTime(2006, 3, 4), MinQuantity = 4, MaxQuantity = 5 };
            new PersistenceSpecification<SpecialOffer>(session)
            .CheckProperty(p => p.Category, specialOffer.Category)
            .CheckProperty(p => p.Description, specialOffer.Description)
            .CheckProperty(p => p.DiscountPct, specialOffer.DiscountPct)
            .CheckProperty(p => p.EndDate, specialOffer.EndDate)
            .CheckProperty(p => p.MaxQuantity, specialOffer.MaxQuantity)
            .CheckProperty(p => p.MinQuantity, specialOffer.MinQuantity)
            .CheckProperty(p => p.StartDate, specialOffer.StartDate)
            .CheckProperty(p => p.Type, specialOffer.Type)
            .VerifyTheMappings();
        }

        [Test]
        public void PhoneContact_Test()
        {
        }
    }
}
